<?php
class custom extends TagsAbstract {
	/**
	 * 是否是封闭的标签
	 * @var unknown_type
	 */
	static $TAG_CLOSED = true;
	static $html = array();	
	public $config = array();

	public function __construct(){

	}
	
	public function getTagStatus(){
		return self::$TAG_CLOSED;
	}

	/**
	 * 返回模板文件路径
	 */
	public function getTemplateFile($tpl = '') {
		//返回需要渲染的模板
		$file = $this->attr ['style'];
		if(!empty($tpl)){
			$file = $tpl;
		}
		return dirname(__FILE__).'/custom/'.$file.'.html';
	}

	/**
	 * 这里返回的是模板中需要渲染的变量
	 */
	public function replace($checkCache) {
		if(strpos(strtoupper($this->attr['sql']),'INSET') === false && strpos(strtoupper($this->attr['sql']),'UPDATE') === false && strpos(strtoupper($this->attr['sql']),'DELETE') === false){
			$var['data'] = M()->query($this->attr['sql']);
		}
	
		
		return $var;
	}
	
	


	public function replaceTag($attr, $value = '', $tagInfo) {
		$this->init ( $attr ,$value);
		$widgetDao = model ( 'Widget' );
		//$checkCache = $widgetDao->checkCache ( $this->sign );
		//if (! $checkCache) {
			//静态数据
		//	$content = $widgetDao->getCache ( $this->sign );
		//} else {
			//动态数据，需要重新渲染
			//从数据库以及模板文件内获取样式
			if(empty($value)){
				$content = $widgetDao->getTemplateByPluginId($this->sign);
			}else{
				$content = $value;
			}
			ob_start ();
			ob_implicit_flush ( 0 );
			$var = $this->replace ( $checkCache );
			extract ( $var, EXTR_OVERWRITE );
			include $this->bulidCache ($content);
			$content = ob_get_clean ();
			//$widgetDao->saveCache ( $this->sign, $content );
		//}
		return $content;
	}
}
?>